package com.javasm.crm.service.impl.productimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.crm.domin.criteria.ProductCriteria;
import com.javasm.crm.domin.criteria.SupplierCriteria;
import com.javasm.crm.domin.entity.productEntity.GoodsSupplierVo;
import com.javasm.crm.domin.entity.productEntity.ProductInfo;
import com.javasm.crm.domin.entity.productEntity.ProductVo;
import com.javasm.crm.mapper.goodsmapper.GoodsSupplierVoMapper;
import com.javasm.crm.mapper.goodsmapper.ProductVoMapper;
import com.javasm.crm.service.productservice.GoodsSupplierVoService;
import com.javasm.crm.service.productservice.ProductVoService;
import com.javasm.crm.utils.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * @Author：zhangyang
 * @Version：1.0
 * @Date：2021/7/12-17:00
 * @desp:
 * @since:
 */
@Service
@Transactional
public class GoodsSupplierVoServiceImpl extends ServiceImpl<GoodsSupplierVoMapper, GoodsSupplierVo> implements GoodsSupplierVoService {
    @Autowired
    GoodsSupplierVoMapper goodsSupplierVoMapper;
    @Override
    public PageResult<GoodsSupplierVo> searchPageByCriteria(SupplierCriteria supplierCriteria) {
        Integer currentPage = supplierCriteria.getCurrentPage();
        Integer pageSize = supplierCriteria.getPageSize();
        if (StringUtils.isEmpty(currentPage)) {
            currentPage=1;
        }
        if (StringUtils.isEmpty(pageSize)) {
            pageSize=5;
        }
        System.out.println(supplierCriteria.getSupplierId());
        QueryWrapper<GoodsSupplierVo> exampleQueryWrapper = new QueryWrapper<>();
        if (supplierCriteria.getPickStatus()==0){
            exampleQueryWrapper.eq("gi.pick_status",0);
        }
        if (supplierCriteria.getPickStatus()==1){
            exampleQueryWrapper.eq("gi.pick_status",1);//代表已选
        }
        if (!StringUtils.isEmpty(supplierCriteria.getSupplierId())){
            exampleQueryWrapper.eq("gs.supplier_id",supplierCriteria.getSupplierId());
        }
        Page<GoodsSupplierVo> examplePage = new Page<>(currentPage, pageSize);
        List<GoodsSupplierVo> queryall = goodsSupplierVoMapper.queryall(examplePage, exampleQueryWrapper);

        return new PageResult<GoodsSupplierVo>(examplePage.getTotal(), queryall);
    }


}
